from PyQt5.QtGui import QPixmap
from PyQt5.QtWidgets import QApplication,QWidget,QHBoxLayout,QVBoxLayout
from PyQt5.QtWidgets import QPushButton,QRadioButton,QButtonGroup
import sys

def on_group_Toggled(btn: QRadioButton):
    print(btn.text(),btn.isChecked())
 
def on_bin_click():
    print("女bin click")  
      
    #给按钮添加/关联点击事件（函数）
if __name__ == '__main__':
    # 创建应用程序
    app = QApplication(sys.argv)
    # 创建窗口
    w = QWidget()
    #设置窗口标题
    w.setWindowTitle("对话框")
    #  创建水平布局 HorizontalLayout    垂直布局 VerticalLayout
    root_layout = QHBoxLayout(w)
    
    btn1 = QRadioButton("男")
    btn2 = QRadioButton("女")
    
    root_layout.addWidget(btn1)
    root_layout.addWidget(btn2)
    btn1.setChecked(True)
    btn2.clicked.connect(on_bin_click)
    
    # 把两个单选按钮添加到QButtonGroup,给它们关联一个函数
    group = QButtonGroup()
    group.addButton(btn1)
    group.addButton(btn2)
    group.buttonToggled.connect(on_group_Toggled)
    
    #显示窗口
    #提交  
    w.show()

    #等待窗口停止
    sys.exit(app.exec())